package cn.wsalix.msg.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.anlaser.service.impl.SimpleServiceImpl;
import cn.anlaser.utils.SearchFilter;
import cn.anlaser.utils.SearchFilter.Operator;
import cn.wsalix.msg.entity.Notice;
import cn.wsalix.msg.repository.NoticeRepository;
import cn.wsalix.msg.service.NoticeService;
import cn.wsalix.user.form.NoticeForm;

@Service("noticeService")
public class NoticeServiceImpl extends
		SimpleServiceImpl<NoticeForm, NoticeRepository, Notice> implements
		NoticeService {
	@Autowired
	private NoticeRepository noticeRepository;
	@Override
	public String module() {
		return "/admin/notice";
	}

	@Override
	public NoticeRepository getRepository() {
		return noticeRepository;
	}
	@Override
	public Class<Notice> getEntityClazz() {
		return Notice.class;
	}

	@Override
	public Map<String, SearchFilter> buildByForm(NoticeForm form) {
		Map<String, Object> searchParams = new HashMap<String, Object>();
		Map<String, SearchFilter> filters = SearchFilter.parse(searchParams);
		if (form.getName() != null && !form.getName().trim().equals("")) {
			filters.put("name",
					new SearchFilter("name", Operator.LIKE, form.getName()));
		}
		return filters;
	}

}
